﻿<?php
require_once('common.php');
/*curl模拟get提交*/
echo "<h2>curl模拟get提交</h2>";
$url = getHost() . "spiders/test.php?info=你好";

//初始化
$ch = curl_init();
//设置选项，包括URL
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
//执行并获取HTML文档内容
$output = curl_exec($ch);
echo "<h2>输出curl_getinfo相关信息</h2>";
$info = curl_getinfo($ch);
dumpArr($info);
//释放curl句柄
curl_close($ch);
//打印获得的数据
print_r($output);


echo "<h2>curl模拟post提交</h2>";
$url = getHost() . "spiders/test.php";
//$post_data = array("info" => "你好");
//$post_data="info=".urlencode('你好');
$post_data="info=你好";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// post数据
curl_setopt($ch, CURLOPT_POST, 1);
// post的变量
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
$output = curl_exec($ch);
echo "<h3>输出curl_getinfo相关信息</h3>";
$info = curl_getinfo($ch);
dumpArr($info);
curl_close($ch);
//打印获得的数据
print_r($output);
?>
